package stu.kurs.security;

import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Properties;
import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.AuthenticationHandler;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;

public class CustomRealm extends AppservRealm {
 
    @Override
    public Enumeration<String> getGroupNames( String string ) throws InvalidOperationException, NoSuchUserException {
        return Collections.enumeration( Arrays.asList( "users", "admins" ) );
    }

    @Override
    protected void init( Properties props ) throws BadRealmException, NoSuchRealmException {
        super.init( props );
        
        System.err.println("-------------Realm-------------");
        
        if( props.containsKey( JAAS_CONTEXT_PARAM ) )
            setProperty( JAAS_CONTEXT_PARAM, props.getProperty( JAAS_CONTEXT_PARAM ) );
    }

    @Override
    public AuthenticationHandler getAuthenticationHandler() {
        return null;
    }

	@Override
	public String getAuthType() {
		return "custom";
	}

}
